package pars.itqiqi.handler.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description 处理登录请求的拦截器
 * @date 2022-07-13 15:57
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String token = request.getHeader("token");

        if (token != null && !token.equals("")) {
            return true;
        } else {
            response.setContentType("application/json; charset=utf-8");
            response.getWriter().print("您没有登录！！");
            return false;
        }
    }
}
